import requests


class Request:

    @classmethod
    def get(self, **kwargs):
        url = kwargs.get('url')
        data = kwargs.get('data', '')
        header = kwargs.get('header')
        method = kwargs.get('method').upper()
        encode = kwargs.get('encode')
        verify = kwargs.get('verify')
        timeout = int(kwargs.get('timeout'))
        datatype = self.dataType(header)
        if datatype is True or method == 'POST':
            response = requests.request(method=method, url=url, data=data, headers=header, verify=verify,
                                        timeout=timeout)
        else:
            response = requests.request(method=method, url=url, params=data, headers=header, verify=verify,
                                        timeout=timeout)
        response.encoding = encode
        return response

    @classmethod
    def dataType(self, headers: dict):
        try:
            htype = headers.get('Content-Type')
            if 'application/json' in htype:
                return True
        except:
            return False
